﻿using AutoMapper;
using B.S.Outsourcing.Domain;
using B.S.Outsourcing.ErrorCode;
using B.S.Outsourcing.Infatructrue;
using B.S.Outsourcing.Read.Api.Application.Command;
using MediatR;

namespace B.S.Outsourcing.Read.Api.Application.CommandHandler
{
    public class GetOutSourIDCommandHandler : IRequestHandler<GetOutSourIDCommand, ApiPaging<OutsourcingModel>>
    {
        private readonly IBaseRepository<OutsourcingModel> baseRepository;
        private readonly IMapper mapper;

        public GetOutSourIDCommandHandler(IBaseRepository<OutsourcingModel> baseRepository, IMapper mapper = null)
        {
            this.baseRepository = baseRepository;
            this.mapper = mapper;
        }

        public async Task<ApiPaging<OutsourcingModel>> Handle(GetOutSourIDCommand request, CancellationToken cancellationToken)
        {
            ApiPaging<OutsourcingModel> result = new ApiPaging<OutsourcingModel>();
            var list = from a in baseRepository.GetAll()
                       where request.Id.Contains(a.Id) select  new OutsourcingModel
                       {
                           Id = a.Id,
                           Name=a.Name,
                           Abbreviation = a.Abbreviation,
                           Status = a.Status,
                           Address = a.Address,
                           PostalCode = a.PostalCode,
                           Telephone = a.Telephone,
                           Remarks = a.Remarks,
                           ContactPerson = a.ContactPerson,
                           Mobile = a.Mobile,
                           Bank = a.Bank,
                           BankAddressPhone = a.BankAddressPhone,
                           AccountNumber = a.AccountNumber,
                           TaxId = a.TaxId,
                       };
            //baseRepository.GetAll().Where(request.Id.Contains(p));
            result.Code = ApiEnums.成功;
            result.Message = "成功";
            result.list = list.ToList();
            return await Task.FromResult(result);
        }
    }
}
